package com.jiyun.h2303b.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.h2303b.dao.TbStorageMapper;
import com.jiyun.h2303b.feign.UserFeignService;
import com.jiyun.h2303b.pojo.TbStorage;
import com.jiyun.h2303b.service.TbStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TbStorageServiceImpl extends ServiceImpl<TbStorageMapper, TbStorage> implements TbStorageService {

    @Autowired
    private UserFeignService userFeignService;

    @Override
    public void deduct(String commodityCode, int count) {
        QueryWrapper<TbStorage> query = new QueryWrapper<>();
        query.eq("commodity_code",commodityCode);
        TbStorage tbStorage =  this.baseMapper.selectOne(query);
        tbStorage.setCount(tbStorage.getCount()-count);
        this.baseMapper.updateById(tbStorage);

        userFeignService.change(1,"心悦5");

    }
}
